using System.IO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
using netcoreApi.service;

namespace netcoreApi
{
    /// <summary>
    /// 配置API类
    /// </summary>
    public class Startup
    {
        /// <summary>
        /// 构造
        /// </summary>
        /// <param name="configuration"></param>
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        /// <summary>
        /// Configuration
        /// </summary>
        /// <value></value>
        public IConfiguration Configuration { get; }

        /// <summary>
        /// This method gets called by the runtime. Use this method to add services to the container.
        /// </summary>
        /// <param name="services"></param>
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services.AddSingleton<ISingleService, SingleService>();
            services.AddTransient<ITransientService, TransientService>();
            services.AddScoped<IScopeService, ScopeService>();


            // //swagger注入
            // services.AddSwaggerGen(c=>{
            //     c.SwaggerDoc("api",new OpenApiInfo(){
            //         Version = "1.0",
            //         Title = "My API",
            //         Description = "APi描述",
            //         Contact = new OpenApiContact(){
            //             Name = "LJQ",
            //             Email = "9646414088@qq.com",
            //             Url = new Uri("http://www.baidu.com")
            //         }
            //     });
            //     string swaggerFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"SwaggerDemo.xml");
            //     c.IncludeXmlComments(swaggerFilePath);
            // });
        }

        /// <summary>
        /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        /// </summary>
        /// <param name="app"></param>
        /// <param name="env"></param>
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            // //swagger
            // app.UseSwagger();
            // app.UseSwaggerUI(c=>{
            //     c.SwaggerEndpoint("/swagger/api/swagger.json","test1");
            // });

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
    }
}
